<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

if(($db_msg=cron_initialize()) !== true){

	print_r("Connection error");

}else{ 
	$bonus_date = date("Y-m-d",mktime(0, 0, 0 , date('m'), date('d')-1, date("Y")));
	print_r($bonus_date);exit;
	$db=$vars["db"];
	$bonus_date='2011-03-09';
	$r=mysql_query("select a.*,b.amount from gg_users a left join gg_member_cf_calc b on b.uid=a.id where a.status='normal' and a.activated='y' and date_format(a.cdate, '%Y-%m-%d')<='".$bonus_date."'");
	while($user = mysql_fetch_assoc($r))
	{
		if($user['matrix_position']==1)
			$dist[$user['matrix_upline']]['left']['id']=$user['id'];
		if($user['matrix_position']==2)
			$dist[$user['matrix_upline']]['right']['id']=$user['id'];
		
		$dist[$user['id']]['left']['bv']=0;
		$dist[$user['id']]['right']['bv']=0;
		$dist[$user['id']]['matrix_upline']=$user['matrix_upline'];
		$dist[$user['id']]['matrix_position']=$user['matrix_position'];
		$dist[$user['id']]['m1']=0;
		$dist[$user['id']]['m2']=0;
		$dist[$user['id']]['m3']=0;
		$dist[$user['id']]['s']=0;
		$dist[$user['id']]['j']=0;
		$dist[$user['id']]['w']=0;
		$dist[$user['id']]['cf']=$user['amount']+0;
		$dist[$user['id']]['ps']=0;
		$dist[$user['id']]['pgs']=0;
		
		$dist[$user['id']]['jackpot'] = number_format(mysql_result(mysql_query("select volume_type from gg_member_comm where type='j' and uid=".$user['id']." order by volume_type desc limit 1"), 0)) or 0;
	}
		
	$rs_sales=mysql_query("select c.id,c.ref,d.total_sponsor_2, b.bv from gg_purchase a inner join gg_sales_bv b on a.id=b.slid inner join gg_users c on c.id=b.uid inner join gg_users d on d.id=c.ref where a.status='confirmed' and date_format(a.cdate, '%Y-%m-%d')='".$bonus_date."' ");
	while($sales = mysql_fetch_assoc($rs_sales)){
		$dist[$sales['id']]['ps']+=$sales['bv'];
		$dist[$sales['id']]['pgs']+=$sales['bv'];
		$matrix_upline=$dist[$sales['id']]['matrix_upline'];
		while($matrix_upline>0){
			$dist[$matrix_upline]['pgs']+=$sales['bv'];
			$matrix_upline=$dist[$matrix_upline]['matrix_upline'];
		}
	}
	/*
	foreach ($dist as $id=>$avalue) {
		$exist=mysql_result(mysql_query("select id from gg_member_comm_sum where uid=".$id." and bonus_date='".$bonus_date."'"), 0) or 0;
		if($exist>0)
			$sql = "UPDATE gg_member_comm_sum SET pgs=".$avalue['pgs']." WHERE uid=".$id." and bonus_date='".$bonus_date."'";
		else
			$sql = "INSERT INTO gg_member_comm_sum SET pgs=".$avalue['pgs'].",uid=".$id.",bonus_date='".$bonus_date."'";
		mysql_query($sql);
	}	
	*/
	print_r($bonus_date.'-done');exit;
	//mysql_query("truncate gg_member_cf_calc");
	foreach ($dist as $id=>$avalue) {		
		$sql = "INSERT INTO gg_member_cf SET uid=".$id.",leg=".$avalue['matrix_position'].",volume_type=".$avalue['pgs'].",amount=".($avalue['cf']+$avalue['pgs']).",cdate='".$bonus_date."'";
		//mysql_query($sql);
		$sql = "INSERT INTO gg_member_cf_calc SET uid=".$id.",amount=".($avalue['cf']+$avalue['pgs']);
		//mysql_query($sql);
		
		if($dist[$id]['matrix_position']==1)
			$dist[$dist[$id]['matrix_upline']]['left']['bv']=($avalue['cf']+$avalue['pgs'])+0;
		if($dist[$id]['matrix_position']==2)
			$dist[$dist[$id]['matrix_upline']]['right']['bv']=($avalue['cf']+$avalue['pgs'])+0;
			
		if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=20000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=20000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==0){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='1',amount=2000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-20000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='1',amount=2000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-20000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=40000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=40000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==1){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='2',amount=4000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-40000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='2',amount=4000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-40000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=80000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=80000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==2){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='3',amount=8000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-80000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='3',amount=8000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-80000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=160000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=160000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==3){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='4',amount=16000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-160000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='4',amount=16000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-160000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=320000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=320000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==4){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='5',amount=32000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-320000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='5',amount=32000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-320000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=640000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=640000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==5){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='6',amount=64000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-640000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='6',amount=64000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-640000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=1280000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=1280000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==6){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='7',amount=128000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-1280000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='7',amount=128000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-1280000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=2560000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=2560000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==7){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='8',amount=256000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-2560000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='8',amount=256000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-2560000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=5120000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=5120000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==8){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='9',amount=512000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-5120000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='9',amount=512000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-5120000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}elseif($dist[$dist[$id]['matrix_upline']]['left']['bv']>=10240000 && $dist[$dist[$id]['matrix_upline']]['right']['bv']>=10240000 && $dist[$dist[$id]['matrix_upline']]['jackpot']==9){
			if($dist[$dist[$id]['matrix_upline']]['left']['bv']>=$dist[$dist[$id]['matrix_upline']]['right']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",type='j',volume_type='10',amount=1024000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['right']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-10240000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
			if($dist[$dist[$id]['matrix_upline']]['right']['bv']>=$dist[$dist[$id]['matrix_upline']]['left']['bv']){
				$sql = "INSERT INTO gg_member_comm SET uid=".$dist[$id]['matrix_upline'].",from_uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",type='j',volume_type='10',amount=1024000,leg1=1,leg1_id=".$dist[$dist[$id]['matrix_upline']]['left']['id'].",leg1_amount='".$dist[$dist[$id]['matrix_upline']]['left']['bv']."',leg2=2,leg2_id=".$dist[$dist[$id]['matrix_upline']]['right']['id'].",leg2_amount='".$dist[$dist[$id]['matrix_upline']]['right']['bv']."',bonus_date='".$bonus_date."',cdate='".$cdate."'";
				print_r($sql."<br>");//mysql_query($sql);
			
				$sql = "UPDATE gg_member_cf_calc SET amount=0 WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
				$sql = "UPDATE gg_member_cf_calc SET amount=".($dist[$dist[$id]['matrix_upline']]['left']['bv']-10240000)." WHERE uid=".$dist[$dist[$id]['matrix_upline']]['left']['id'];
				//mysql_query($sql);
			}
		}
	}
		
	print_r("finish<br>");
}
?>